//
//  MyFunction.cpp
//  firebkball
//
//  Created by ren jian on 18/5/31.
//
//

#include "MyFunction.h"

#include <time.h>

int MyFunction::atoi(const char *str)
{
    bool isToIntValid =true;
    long long num = 0;
    int mark = (*str== '-' ? -1: 1);
    long long upperBound = numeric_limits<int>::max();
    if(mark == -1)
        ++upperBound;
    const char* temp = (*str == '+' || *str == '-') ? str + 1: str;
    for( ;*temp >= '0' && *temp <= '9'; ++temp)
    {
        num = num * 10 + *temp - '0';
        if(num > upperBound)
        {
            isToIntValid = false;
            num = upperBound;
            break;
        }
    }
    if(*temp !='\0' || *str == '0')
        isToIntValid = false;
    return  static_cast<int>(mark * num);
}

string MyFunction::getTimeFormat()
{
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S",localtime(&timep) );
    return tmp;
}

string MyFunction::getToday()
{
    time_t timep;
    time (&timep);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y-%m-%d",localtime(&timep) );
    return tmp;
}